package com.hctforgreen.greenservice.model;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 6.15、获取将要进行的考试信息接口
 * @author Tallen Zhai
 *
 */
public class PaperEntity extends BaseEntity {

	private static final long serialVersionUID = -7318621047372984172L;

	public List<DataEntity> dataList = null;
	
	public String state = "";
	public String id = "";
	public String title = "";
	public String date = "";
	public String times = "";
	public String subjectNum = "";
	public String totalPoint = "";
	
	public final static String STATE = "state";
	public final static String ID = "id";
	public final static String TITLE = "title";
	public final static String DATE = "date";
	public final static String TIMES = "times";
	public final static String SUBJECT_NUM = "subjectNum";
	public final static String TOTAL_POINT = "totalPoint";
	private final static String BODY = "body";
	
	public static PaperEntity parse(JSONObject jsonObject)throws JSONException{
		PaperEntity bean = new PaperEntity();
		if(jsonObject.has(STATE)){
			bean.state = jsonObject.getString(STATE);
		}
		if(jsonObject.has(ID)){
			bean.id = jsonObject.getString(ID);
		}
		if(jsonObject.has(TITLE)){
			bean.title = jsonObject.getString(TITLE);
		}
		if(jsonObject.has(DATE)){
			bean.date = jsonObject.getString(DATE);
		}
		if(jsonObject.has(TIMES)){
			bean.times = jsonObject.getString(TIMES);
		}
		if(jsonObject.has(SUBJECT_NUM)){
			bean.subjectNum = jsonObject.getString(SUBJECT_NUM);
		}
		if(jsonObject.has(TOTAL_POINT)){
			bean.totalPoint = jsonObject.getString(TOTAL_POINT);
		}
		
		/**
		 * 解析body节点
		 */
		if (jsonObject.has(BODY)) {
			
			JSONArray jsonArray = jsonObject.getJSONArray(BODY);
				
			bean.dataList = new ArrayList<DataEntity>();
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject object = jsonArray.getJSONObject(i);
				DataEntity entity = DataEntity.parse(object);
				bean.dataList.add(entity);
			}
			
		}
		
		return bean;
	}
	public static class DataEntity extends BaseEntity {

		private static final long serialVersionUID = 8988744547631832363L;
		public String t_id = "";
		public String t_name = "";
		//============只在页面中用到==============
		public boolean isChecked = false;
		
		public final static String KNO_ID = "t_id";
		public final static String SUBJECT = "t_name";
		public static DataEntity parse(JSONObject jsonObject)
				throws JSONException {
			DataEntity bean = new DataEntity();
			if (jsonObject.has(KNO_ID)) {
				bean.t_id = jsonObject.getString(KNO_ID);
			}
			if (jsonObject.has(SUBJECT)) {
				bean.t_name = jsonObject.getString(SUBJECT);
			}
			return bean;
		}
	}
}
